package com.ruoyi.web.controller.student_club.admin_controller;

import java.util.List;

import com.ruoyi.student_club.vo.ClubMemberVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.student_club.domain.ClubMember;
import com.ruoyi.student_club.service.IClubMemberService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社员管理Controller
 * 
 * @author 无尤
 * @date 2022-01-24
 */
@Controller
@RequestMapping("/member/member")
public class ClubMemberController extends BaseController
{
    private String prefix = "member/member";

    @Autowired
    private IClubMemberService clubMemberService;

    @RequiresPermissions("member:member:view")
    @GetMapping()
    public String member()
    {
        return prefix + "/member";
    }

    /**
     * 查询社员管理列表
     */
    @RequiresPermissions("member:member:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClubMember clubMember)
    {
        startPage();
        List<ClubMemberVo> list = clubMemberService.selectClubMemberList(clubMember);
        return getDataTable(list);
    }

    /**
     * 导出社员管理列表
     */
    @RequiresPermissions("member:member:export")
    @Log(title = "社员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClubMember clubMember)
    {
        List<ClubMemberVo> list = clubMemberService.selectClubMemberList(clubMember);
        ExcelUtil<ClubMemberVo> util = new ExcelUtil<ClubMemberVo>(ClubMemberVo.class);
        return util.exportExcel(list, "社员管理数据");
    }

    /**
     * 修改社员管理
     */
    @RequiresPermissions("member:member:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ClubMember clubMember = clubMemberService.selectClubMemberById(id);
        mmap.put("clubMember", clubMember);
        return prefix + "/edit";
    }

    /**
     * 修改保存社员管理
     */
    @RequiresPermissions("member:member:edit")
    @Log(title = "社员管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClubMember clubMember)
    {
        return toAjax(clubMemberService.updateClubMember(clubMember));
    }

    /**
     * 删除社员管理
     */
    @RequiresPermissions("member:member:remove")
    @Log(title = "社员管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clubMemberService.deleteClubMemberByIds(ids));
    }
}
